<?php 
session_start();
if (!isset($_SESSION['username'])) {
	header('location:/setup/');
}

$home_title = isset($_POST['home_title'])? $_POST['home_title']:"";
$title = isset($_POST['title'])? $_POST['title']:"";

if($home_title=="" || $title=="") {
    header('location:/setup/');
    exit();
}

$pagename1 = isset($_POST['pagename1'])? $_POST['pagename1']:"";
$pagename2 = isset($_POST['pagename2'])? $_POST['pagename2']:"";

$myfile = fopen("config.txt", "w") or die("打开配置文件错误!");

fwrite($myfile,"# home为网页标题\n");
fwrite($myfile,"home=".$home_title."\n\n");
fwrite($myfile,"# title 为导航网页中的标题\n");
fwrite($myfile,"title=".$title."\n\n");

fwrite($myfile,"# page为右上角的翻页按钮，如果不需要，可以把该项前加 # 注释掉。\n");
fwrite($myfile,"page=".$pagename1.";".$pagename2."\n\n");

fwrite($myfile,"#page1为第一个页面的导航设置，分为标题名称，图标名称，网址，中间用分号分开。\n");

$page1name = isset($_POST['page1name'])? $_POST['page1name']:array();
$page1img = isset($_POST['page1img'])? $_POST['page1img']:array();
$page1url = isset($_POST['page1url'])? $_POST['page1url']:array();


for ($i = 0; $i < 24; $i++){
    $name = $i< count($page1name)? $page1name[$i]: "";
    $img = $i< count($page1img)? $page1img[$i]: "";
    $url = $i< count($page1url)? $page1url[$i]: "";
    if($name=='' || $img=='' || $url=='') continue;
    fwrite($myfile,"page1=".$name.";".$img.";".$url."\n");
}

fwrite($myfile,"#page2为第二个页面的导航设置，分为标题名称，图标名称，网址，中间用分号分开。\n");


$page2name = isset($_POST['page2name'])? $_POST['page2name']:array();
$page2img = isset($_POST['page2img'])? $_POST['page2img']:array();
$page2url = isset($_POST['page2url'])? $_POST['page2url']:array();

for ($i = 0; $i < 24; $i++){
    $name = $i< count($page2name)? $page2name[$i]: "";
    $img = $i< count($page2img)? $page2img[$i]: "";
    $url = $i< count($page2url)? $page2url[$i]: "";
    if($name=='' || $img=='' || $url=='') continue;
    fwrite($myfile,"page2=".$name.";".$img.";".$url."\n");
}


fclose($myfile);
$_SESSION['msg'] = "提交成功，请刷新导航页查看效果。";
header('location:/setup/');


?>